<?php
/**
 *@file commentreport.php
 *@author Zhe.Zhou(zhouzhe@haibao.com)
 *@date 2015-7-29 下午4:19:39
 *@brief  
 */
namespace haibao\app\business;

class CommentReport extends Base{

    /**
     * @var $_instance
     */
    private static $_instance;
    
    /**
     * instance()
     */
    private static function instance(){
        if(!self::$_instance){
            self::$_instance = new \haibao\app\data\CommentReport();
        }
        return self::$_instance;
    }
    
	public static function updateComment($id,$arrSet){
		\haibao\cms\business\Base::checkOperation(\haibao\cms\business\Base::FUNC_CODE_APP_COMMENT);
		$arrSet['ProcessTime'] = date('Y-m-d H:i:s');
		$arrSet['ProcessUserId'] = self::getCurrentUser()->Id;
		self::instance()->updateByReportId($id, $arrSet);
		if(is_array($id)){
		    foreach($id as $key=>$val){
		        $comment = \haibao\app\business\Comment::getCommentById($val);
		        $commentData = new \haibao\app\data\Comment();
		        if($comment){
		            $commentData->deleteCommentCache($comment->ObjectId);
		        }
		    }
		}else{
		    $comment = \haibao\app\business\Comment::getCommentById($id);
		    $commentData = new \haibao\app\data\Comment();
		    if($comment){
		        $commentData->deleteCommentCache($comment->ObjectId);
		    }
		}
		
		\haibao\cms\business\Base::saveOperateHistory(\haibao\cms\business\Base::FUNC_CODE_APP_COMMENT, $arrSet);
	}

	/**
	 * 举报其他用户评论
	 * @param \haibao\app\model\data\CommentReport $model
	 */
	public static function reportComment($model){
	    if(!$model->CommentId || !$model->UserId || !$model->ReportUserId){
	        throw new BusinessException('参数不正确', self::DATA_ERROR_CODE_EMPTY);
	    }
	    if($model->UserId == $model->ReportUserId){
	        throw new BusinessException('不能举报自己的评论', self::DATA_ERROR_CODE_SYSTEM);
	    }
	    
	    $comment = \haibao\app\business\Comment::getCommentById($model->CommentId);
	    if(!$comment){
	        throw new BusinessException('被举报的评论内容不存在', self::DATA_ERROR_CODE_SYSTEM);
	    }
	    $model->Content = $comment->Content;
	    $model->CreateTime = new \DateTime();
	    $model->Status = \haibao\app\model\data\CommentReport::STATUS_NOT_YET;
	    self::instance()->saveReport($model);
	}

}